package csse3004.GD.SysAdmin;

/**
 * @author Mamdouh Alharbi- s4194298
 */
import csse3004.GD.USTemp;


import csse3004.GD.DA.SysAdminDA;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.ModelAndView;
import java.util.ArrayList;
import javax.servlet.ServletException;

public class UserSearchController extends SimpleFormController {

    private SysAdminService sysAdminService = new SysAdminDA();

    @Override
    public ModelAndView onSubmit(Object command) throws ServletException {
        UserSearch searchy = (UserSearch) command;
        String searchword = searchy.getSearchword();
        String searchtype = searchy.getSearchtype();
        double lon = Double.parseDouble(searchy.getLon());
        double lat = Double.parseDouble(searchy.getLat());
        int range = Integer.parseInt(searchy.getRange());

        ArrayList<USTemp> searchResults = new ArrayList<USTemp>();

        if (searchtype.equals("location")) {
//            searchResults = sysAdminService.getUsersByLocation(lon,lat,range);
            logger.info("longitude:"+lon+" latitude:"+lat+" range:"+range);
        } else if (searchtype.equals("organisation")) {
            searchResults = sysAdminService.getUsersByOrganisation(searchword);
        }
        return new ModelAndView("usResult", "searchResult", searchResults);
    }
}